package com.rjwh.dingdong.client.mvp.presenter.impl;

import android.content.Context;

import com.aishua.lib.task.AsResult;
import com.rjwh.dingdong.client.constant.NetConstant;
import com.rjwh.dingdong.client.mvp.BasePresenter;
import com.rjwh.dingdong.client.mvp.model.impl.MoreBabyInfoModel;
import com.rjwh.dingdong.client.mvp.presenter.IMoreBabyInfoPresenter;
import com.rjwh.dingdong.client.mvp.view.MoreBabyInfoView;
import com.rjwh.dingdong.client.util.ToastUtil;

/**
 * @author Kay
 * @ClassName MoreBabyInfoPresenter
 * @Description
 * @date 2016-7-30
 * @history 2016-7-30 author: description:
 */
public class MoreBabyInfoPresenter extends BasePresenter<MoreBabyInfoView> implements IMoreBabyInfoPresenter {

    private MoreBabyInfoModel model;

    public MoreBabyInfoPresenter(Context context, MoreBabyInfoView mMvpView) {
        super(context, mMvpView);
        model = new MoreBabyInfoModel(this);
    }

    @Override
    public void onServerDataAcquired(int businessType, AsResult mAsResult, boolean isRefresh) {
        if (isViewAttached()) {
            getMvpView().dismissLoading();
            switch (businessType) {
                case NetConstant.SAVEBABYDATA:
                    if (mAsResult.getResultCode() > NetConstant.MSG_CONNECT_SUCCESS) {
                        ToastUtil.showToast(getContext(), "修改成功");
                        getMvpView().loadData();
                    } else if (mAsResult.getResultMsg() != null) {
                        ToastUtil.showToast(getContext(), mAsResult.getResultMsg());

                    }
                    break;

                default:
                    break;
            }
        }
    }

    @Override
    public void detachView() {
        model.detachView();
        detachViews();
    }

    /**
     * 修改宝宝资料
     *
     * @param value 修改的数据
     * @param type  修改的类型(姓名,年龄等)
     */
    @Override
    public void saveBabyData(String value, String type) {
        if (isViewAttached()) {
            getMvpView().showLoading();
            model.saveBabyData(value, type);
        }
    }
}
